package com.client.task;

import android.content.Context;
import android.os.AsyncTask;

import com.client.bean.BirdList;
import com.client.db.DataService;

public class NoOrderBirdMessagesTask extends AsyncTask<BirdList, Void, Integer> {
	public interface Callback {

		void onComplete(Integer result);
	}

	private final Context context;
	private Callback callback;

	private DataService mDataService=null;
	public NoOrderBirdMessagesTask(Context context, Callback callback) {
		this.context = context;
		this.callback = callback;
		mDataService=new DataService(context);
	}

	/**
	 * The task should be executed with one given source photo uri.
	 */
	@Override
	protected Integer doInBackground(BirdList... params) {
		if (params[0] == null) {
			return 0;
		} else {
			if (!iscancle) {
//				for (int i = 0; i < 30; i++) {
//					params[0].addBirdMessage(new BirdMessage());
//				}
				mDataService.getBirdListNoOrder(params[0],params[0].key);
			}
		}

		return 1;
	}

	@Override
	protected void onPostExecute(Integer result) {
		// if (result == null) {
		// Toast toast = Toast.makeText(context, R.string.loading_failure,
		// Toast.LENGTH_SHORT);
		// toast.setGravity(Gravity.CENTER, 0, 0);
		// toast.show();
		// }
		if (callback != null) {
			callback.onComplete(result);
		}

	}

	private boolean iscancle = false;

	public void release() {
		callback = null;
	}
}
